﻿javascript:(function (){

function trim (zeichenkette) {
  // Erst führende, dann Abschließende Whitespaces entfernen
  // und das Ergebnis dieser Operationen zurückliefern
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

var the_div = document.getElementById('mw_masthead');
if (document.getElementById('group_creator') == undefined) {
		var the_count=document.createElement("div");
		the_count.id='group_creator';		
		$(the_count).insertBefore(the_div);
		var the_close = document.createElement('a');
		var the_start=document.createElement("a");		    
		the_count.innerHTML='Please give me a name for the group to create: <input type="text" id="group_creator_name"><br><div id="group_creator_logging" style="color:yellow;text-weight:bold"></div>';
		the_start.href='#';
		the_start.id='juansinho_start';
		the_start.className= 'sexy_button_new green short';
		the_start.innerHTML = '<span><span>Start</span></span>';
		the_close.href='#';
		the_close.id='juansinho_close';
		the_close.className= 'sexy_button_new red short';
		the_close.innerHTML = '<span><span>Close</span></span><br><br>';	   
		$(the_close).insertBefore(the_count);		
		$(the_start).insertBefore(the_count);		
} 	
$(the_close).click(function(){
	$('#juansinho_start').remove();
	$('#group_creator_logging').remove();
	$('#group_creator').remove();
	$('#juansinho_close').remove();
	});
	$(the_start).click(function(){
		FB.ui({
		  method: 'game_group_create',
		  name: document.getElementById('group_creator_name').value,
		  description: 'Change the description some day',
		  privacy: 'CLOSED'
		},
		 function(response) {
			if (response && response.id) {
				document.getElementById('group_creator_logging').innerHTML="Group was created with id " + response.id+'. Remember it as you will need it for members to join';
			} else {
				document.getElementById('group_creator_logging').innerHTML='There was an error creating your group. Please try again.';
			}
		 }
		);	
	
	});
return;

})();


